package rai.service.transport;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class Client {
	ObjectOutputStream outToServer;
	ObjectInputStream inToServer;

	public Client(String hostname) throws IOException {
		Socket clientSocket = new Socket(hostname, 8787);
		outToServer = new ObjectOutputStream(clientSocket.getOutputStream());
		inToServer = new ObjectInputStream(clientSocket.getInputStream());
		System.out.println("client init");
	}

	public void writeInt(int i) throws IOException {
		outToServer.writeInt(i);
		outToServer.flush();
	}
	
	public void writeString(String s) throws IOException{
		outToServer.writeUTF(s);
		//System.out.println("envoie "+s);
		outToServer.flush();
	}
	
	public void writeObject(Object object) throws IOException{
		outToServer.writeObject(object);
		outToServer.flush();
	}
	
	public int readInt() throws IOException {
		return inToServer.readInt();
	}
	
	public String readString() throws IOException{
		return inToServer.readUTF(); 
	}
	
	public boolean readBoolean() throws IOException{
		return inToServer.readBoolean();
	}
	
	public Object readObject() throws IOException, ClassNotFoundException{
		return inToServer.readObject();
	}
	
}

